package com.example.fee.listener;

import com.example.fee.service.SysFeeService;
import com.exmaple.cdc.annotation.CDCListener;
import com.exmaple.cdc.listener.CDCMessageListener;
import com.exmaple.cdc.wrap.BinlogAddObj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/14 下午8:49
 */
@CDCListener(tableName = "sys_user_register_message", multiple = false)
public class SysUserAddListener implements CDCMessageListener {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private SysFeeService sysFeeService;

    /*
     * 实时消息处理。
     * @param binlogObj
     */
    @Override
    public void onMessage(Object binlogObj) throws Exception {
        logger.warn("SysUserAddListener receive binlogObj: {}", binlogObj);
        if (binlogObj instanceof BinlogAddObj) {
            this.sysFeeService.addUserFee((BinlogAddObj) binlogObj);
        }
    }

    /*
     * 补偿消息处理.
     * @param map
     */
    @Override
    public void failHandler(Map<String, Object> map) throws Exception {

    }
}
